/**
 * 通用
 */
import request from "@/utils/request";

/**
 * 商品分类树
 */
export const getCategoryTree = (search = "") => {
  return request({
    url: `/mall/tenant/category/getcategoryList?search=${search}`,
    method: "get"
  });
};

/**
 * 获取商品日志
 */
export const getLog = productId => {
  return request({
    url: "/mall/common/product/logs",
    method: "post",
    data: {
      productId
    }
  });
};

/**
 * 工厂端接口
 */
/**
 * 获取工厂端商品列表
 * @param {*} data 条件参数
 * @returns
 */
export const getFactoryList = data => {
  return request({
    url: "/mall/tenant/factory/product/page",
    method: "post",
    data
  });
};

/**
 * 商品下架
 */
export const downFactory = data => {
  return request({
    url: "/mall/tenant/factory/operation/down",
    method: "post",
    data
  });
};
/**
 * 商品上架
 */
export const upFactory = data => {
  return request({
    url: "/mall/tenant/factory/product/listing",
    method: "post",
    data
  });
};
/**
 * 商品重新上架
 */
export const anewUp = data => {
  return request({
    url: "/mall/tenant/factory/product/reListing",
    method: "post",
    data
  });
};

/**
 * 批量修改名称
 */
export const editFactoryName = data => {
  return request({
    url: "/mall/tenant/factory/product/batchChangeProductName",
    method: "post",
    data
  });
};

/**
 * 获取数量
 */
export const getFactoryCount = () => {
  return request({
    url: "/mall/tenant/factory/product/barProductTotal",
    method: "post"
  });
};

/**
 * 撤销下架
 */
export const cancelSoldOut = data => {
  return request({
    url: "/mall/tenant/factory/product/revokeDelisting",
    method: "post",
    data
  });
};

/**
 * 删除商品
 */
export const deleteFactory = data => {
  return request({
    url: "/mall/tenant/factory/product/delProduct",
    method: "post",
    data
  });
};
/**
 * 删除回收站的商品
 */
export const deleteRecycle = data => {
  return request({
    url: "/mall/tenant/factory/recycle/bin/del/product",
    method: "post",
    data
  });
};

/**
 * 恢复商品
 */
export const recoveryFactory = data => {
  return request({
    url: "/mall/tenant/factory/recycle/bin/withdraw/product",
    method: "post",
    data
  });
};


/**
 * 获取用户常用分类列表
 */
export const getUserCategoryList = () => {
  return request({
    url: "/mall/common/commonlyCategory/list",
    method: "post"
  });
};

/**
 * 上传记录
 */
export const getUploadRecord = data => {
  return request({
    url: "/mall/factory/file/logs",
    method: "post",
    data
  });
};
/**
 * 删除导入日志
 */
export const deleteUploadRecord = id => {
  return request({
    url: "/mall/factory/file/deleteLogs",
    method: "post",
    data: { id }
  });
};
/**
 * 模板文件导入
 */
export const importTemplate = (filePath, data) => {
  return request({
    url: `/mall/factory/file/importProductExcel?filePath=${filePath}`,
    method: "post",
    data
  });
};

/**
 * 下载模板
 */
export const downTempFile = categoryId => {
  return request({
    url: "/mall/factory/file/exportProductExcel",
    method: "post",
    responseType: "blob",
    data: { categoryId }
  });
};

/**
 * 保存常用分类
 */
export const saveOftenCategory = categoryId => {
  return request({
    url: "/mall/common/commonlyCategory/save",
    method: "post",
    data: { categoryId }
  });
};

/**
 *商品占用数量查询
 */
export const lockPurchase = data => {
  return request({
    url: "/mall/tenant/factory/product/lockPurchase",
    method: "get",
    params: data
  });
};
/**
 *商品占用数量查询-多商品批量查询
 */
export const batchLockPurchase = data => {
  return request({
    url: "/mall/tenant/factory/product/batch/lockPurchase",
    method: "post",
    data
  });
};
/**
 * 获取商品管理导入状态
 */
export const getInProgressCount = (type=1) => {
  return request({
    url: `/sass/consume/getInProgressCount/${type}`,
    method: "get"
  });
};
